package leetcode;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:栈的弹出顺序
 * User: 东莞呵呵
 * Date:2022-07-14
 * Time:17:23
 */
public class TestDemo3 {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        int i=0;
        int j=0;
        Stack<Integer> stack=new Stack<>();
        while(j< popA.length) {
            while (pushA[i] != popA[j]) {
                stack.push(pushA[i++]);
            }
            j++;
            while (popA[j]==stack.peek()){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
}
